<?PHP

function countwords ($str) {
	return str_word_count($str, 1, '-~`@#$%^&*()_=+{}[]<>/');
};

function countsentence ($str) {
	//return preg_match_all('/[^\!\.\?][^\!\.\?|\s]*[\.|\!|\?]+(?!\w)/',$str,$match);
	
	return preg_match_all('/[A-Za-z][A-Za-z\s]*[\.|\!|\?]+(?!\w)/',$str,$match);
};

function uniquearray ($array) {
	return array_unique($array, SORT_STRING);
};

function topword ($array, $rank) {

	
	$tmp = array_count_values($array);
	arsort($tmp);
	$res = array_keys($tmp);
	
	if ($rank-1 > count($res)){
		echo "</br> Invalid Rank Number input. Max is " .count($res)."</br>";
	} else {
		echo "<be/>" . $res[$rank-1];
	};
};

function countletters ($str) {
	//Strip the string
	$new_string = strtolower(ereg_replace("[^A-Za-z]", "", $str ));
	
	foreach (count_chars($new_string, 1) as $i => $val) {
   		echo "There were $val instance(s) of \"" , chr($i) , "\" in the string.\n";
	};
};

function compText ($text1) {

	//return an array
	$count1 = countwords($text1);
	$sent1 = countsentence($text1);
	$unique1 = uniquearray($count1);
	
	
	echo "Your results for Text1: </br>";
	echo "Word count: " . count($count1) . "</br>";
	echo "Sentence count: " . $sent1 . "</br>";
	echo "Unique word count: " . count($unique1) . "</br>";
	topword($count1,10);
	echo "</br>";
	//countletters($text1);
	echo "</br>";
	
	
	
	//print_r($top1);
	//print_r($count1);
	//print_r($unique1);

};

function compFile ($file1, $file2) {

};

function compURL ($url1, $url2) {

};
?>